import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: LJHomePage(),
    );
  }
}

class LJHomePage extends StatelessWidget {
  const LJHomePage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title:Center(
          child:  Text("基础的widget"),
        ),
      ),
      body: LJHomeContent(),
      floatingActionButton: FloatingActionButton(
        onPressed: (){
          print("float action button click");
        },
        child: Icon(Icons.add),
      ),
    );
  }
}

class LJHomeContent extends StatefulWidget {
  const LJHomeContent({Key key}) : super(key: key);

  @override
  _LJHomeContentState createState() => _LJHomeContentState();
}

class _LJHomeContentState extends State<LJHomeContent> {
  final url = "https://img-blog.csdnimg.cn/2020122719113213.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3psMTg2MDM1NDM1NzI=,size_16,color_FFFFFF,t_70";
  final usernameController = TextEditingController();
  final passwordController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    //1.在flutter项目中创建一个文件夹 存储图片
    //2.在pubspec.yaml 进行配置
    //3.使用图片
    return TextFiledDemo(usernameController: usernameController, passwordController: passwordController);
  }
}

class TextFiledDemo extends StatelessWidget {
  const TextFiledDemo({
    Key key,
    @required this.usernameController,
    @required this.passwordController,
  }) : super(key: key);

  final TextEditingController usernameController;
  final TextEditingController passwordController;

  @override
  Widget build(BuildContext context) {
    return Padding(padding:const EdgeInsets.all(8.0),
      child: Column(
        children: [
          TextField(
            controller: usernameController,
            decoration: InputDecoration(
              labelText: "username",
              icon: Icon(Icons.people),
              hintText: "请输入用户名",
              border:OutlineInputBorder(),

            ),
            onChanged: (value){
              print(value);
            },
            onSubmitted: (value){
              print(value);
            },
          ),
          SizedBox(height: 10),
          TextField(
            controller: passwordController,
            decoration: InputDecoration(
                labelText: "password",
                icon:Icon(Icons.lock),
                border: OutlineInputBorder()
            ),
          ),
          SizedBox(height: 10),
          Container(
            width: 200,
            height: 60,
            child: TextButton(
              child: Text("登 录",style: TextStyle(fontSize: 24,color: Colors.white),),
              style: ButtonStyle(
                  backgroundColor: MaterialStateProperty.all(Colors.blue)
              ),
              onPressed: (){
                final username = usernameController.text;
                final password = passwordController.text;
                print("$username,$password");
              },
            ),
          )
        ],
      ),
    );
  }
}

class FadeImageDemo extends StatelessWidget {
  const FadeImageDemo({
    Key key,
    @required this.url,
  }) : super(key: key);

  final String url;

  @override
  Widget build(BuildContext context) {
    return FadeInImage(placeholder: AssetImage("assets/images/01.jpg"), image: NetworkImage(url));
  }
}